<?php

namespace app\api\controller;


class Explorerate extends Common
{
	 
    
    /**
     * 点赞
     */
    public function praise(){    	
    	// 接收参数
        $this->datas = $this->params;
        // 信息ID
        $explore_tab_id = $this->datas['explore_tab_id'];
        // 用户ID
        $userId = $this->datas['userId'];      
        
        // 点赞默认0
        $praise = 0;      
        if(!empty($this->datas['praise'])){
        	$praise = $this->datas['praise'];
        }
        
        
        $comment = '';      
        if(!empty($this->datas['comment'])){
        	$comment  = $this->datas['comment'];
        }
        
        $rate = 0;      
        if(!empty($this->datas['rate'])){
        	$rate  = $this->datas['rate'];
        }
        
        
        $params = array(
    		"explore_tab_id"=>$explore_tab_id,
    		"userId" => $userId,
    		"praise" => $praise,
    		"comment" => $comment ,
    		"rate" => $rate
        );
        
        $where = " explore_tab_id = '".$explore_tab_id."' and userId = '".$userId."'";
       	$count = db('explore_tab_rate')->where($where)->count();
        
        if($count > 0){
        	db('explore_tab_rate')->where($where)->update($params);
        	$this->returnMsg(400, '新增test表失败！');	
        } else {        	
       		// 往数据库插入文章信息
        	$res = db('explore_tab_rate')->insertGetId($params);
        	$this->returnMsg(200, '新增test表成功！', $res);
 	
        }       
    }
}
?>